package com.ijuit.business.impl.user;

import com.ijuit.business.BusinessServiceImpl;
import com.ijuit.business.interfaces.user.UserService;
import com.ijuit.common.kit.EncryptKit;
import com.ijuit.common.kit.StringKit;
import com.ijuit.common.kit.date.DateKit;
import com.ijuit.model.user.User;

/**
 * 用户信息业务逻辑层服务实现类
 * 
 * @author 罗龙
 *
 */
public class UserServiceImpl extends BusinessServiceImpl<User> implements UserService{

	@Override
	public int login(String loginId, String password) throws Exception {
		if(StringKit.isBlank(loginId) || StringKit.isBlank(password)){
			return -1;
		}
		int userId = User.me.getByLoginId(loginId,EncryptKit.encrypt(password));
		if(userId>0){
			return 1;
		}
		return 0;
	}

	@Override
	public boolean register(User user) throws Exception {
		user.set("password", EncryptKit.encrypt(user.getStr("password")));
		user.set("createTime", DateKit.getNowTime());
		boolean rvalue = user.save();
		System.out.println("用户ID=="+user.getInt("id"));
		return rvalue;
	}


}
